<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="sun.applet.resources.MsgAppletViewer_it"%>
<%@page import="utility.connections"%>
<html>
<script type="text/javascript" src="../js/immagini.js"></script>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
<!--
.style1 {color: #000000}
.style2 {
	color: #FFFFFF;
	font-weight: bold;
}</style>
<head>

<jsp:useBean id="clsConn" scope="session" class="utility.connections"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ELENCO RICHIESTE</title>
</head>
<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        <td align="center"><div align="left">
          <p class="style3">
          
          <%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			String user = session.getAttribute("user").toString();
			String type = session.getAttribute("type").toString();
			String matr = session.getAttribute("matricola").toString();
			String nome = session.getAttribute("nome").toString();
			String cogn = session.getAttribute("cognome").toString();
			}
		%>
		  </p>
        </div></td>
        </tr>
     <tr>
     <div align="left">
   	</div>
   	</tr>
      <tr>
        <td class="style2"><p align="center"><strong>Elenco completo Richieste beni MA MB   </strong></p></td>
        </tr>
      <tr>
        <td class="style1"><div align="center"><input type="button" value="INDIETRO" onclick="history.back()"></input></div></td>
        </tr>
		<tr>
        <td class="style1"><div align="center">
          <table width="100%" cellpadding="2" cellspacing="0" bordercolor="#000000" style="border:1px solid;">
            <tr>
              <td width="8%" bordercolor="#333333" bgcolor="#FFFF99" class="item1" style="border:1px solid;"><div align="center" >PROG.</div></td>
              <td width="17%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=1">CODICE</a></div></td>
              <td width="21%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=2">DIEPNDENTE</a></div></td>
              <td width="21%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=3">COGNOME</a></div></td>
              <td width="21%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=4">NOME</a></div></td>
              <td width="26%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=5">SOTTOCATEGORIA BRNE</a></div></td>
              <td width="21%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=6">DENOMINAZIONE BENE</a></div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_ricDip.jsp?order=7">DATA</a></div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >MOTIVAZIONE</div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >ESITO</div></td>
            </tr>

			
			

<%! String user, codice, dipendente, sottocategoriabene, data, motivazione, esito; 
	Connection conn;
	Statement  st;
	ResultSet  rs;
%>
<%
				
				user = session.getAttribute("user").toString().toLowerCase();
				conn=connections.getConnection();
				st=connections.getStatement();
				int order = Integer.parseInt(request.getParameter("order"));
				String qry="";
				String set="Select codice from sottocategoriabene where (categoriabene='MA' OR categoriabene='MB') and esito!='P'";
				
				qry = "select RICHIESTA.codice,RICHIESTA.dipendente,PERSONALE.cognome,PERSONALE.nome AS nome,RICHIESTA.sottocategoriabene,sottocategoriabene.nome as nomebene,to_char(data,'DD/MM/YYYY') as data,RICHIESTA.motivazione,RICHIESTA.esito from richiesta,PERSONALE, SOTTOCATEGORIABENE where RICHIESTA.sottocategoriabene in ("+set+") AND PERSONALE.matricola=dipendente AND SOTTOCATEGORIABENE.codice=sottocategoriabene";
				
				switch(order)
				{
				case 1: qry += " order by RICHIESTA.codice";     break; 
				case 2: qry += " order by RICHIESTA.dipendente";     break; 
				case 3: qry += " order by PERSONALE.COGNOME";     break; 
				case 4: qry += " order by PERSONALE.NOME";     break; 
				case 5: qry += " order by RICHIESTA.SOTTOCATEGORIABENE";     break; 
				case 6: qry += " order by SOTTOCATEGORIABENE.NOME";     break; 
				case 7: qry += " order by RICHIESTA.DATA";     break; 
				}
				System.out.println(qry);
				ResultSet rs = st.executeQuery(qry);
				int i=0;
				
				if(rs.isBeforeFirst()&&rs.isAfterLast())
				{
					//Avvisare che non ci sono record!!!!
				}
				else
				{
					Statement  stt;
					String title="",titlesottocat="";
					String cognome="",nome="", nomeBene="";
					while (rs.next())
					{
						codice = rs.getString("codice");
						dipendente = rs.getString("dipendente");
						nome=rs.getString("nome");
						cognome=rs.getString("cognome");
						sottocategoriabene=rs.getString("sottocategoriabene");
						nomeBene=rs.getString("nomeBene");
						data=rs.getString("data");
						motivazione=rs.getString("motivazione");
						esito=rs.getString("esito");
						
						String color;
	              		String bordercell;
	              		
	              		i++;
	              		
	              		if (i%2==0)
	              		{
	              			color ="\"#E0E0E0\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		else
	              		{
	              			color = "\"#EFFFEF\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		
	              		out.println("<tr>");
	              		out.println("<td align=\"right\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+" title=\"ciauz\">"+ i +"</a></td>"); //prog.
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ " >" + codice + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ " title=\""+title+"\" >" + dipendente + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + cognome + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + nome + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ " title=\""+titlesottocat+"\" >" + sottocategoriabene + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ " >" + nomeBene + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + data + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + motivazione + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + esito + "</td>");
	              		out.println("</tr>");
					}	
				}
				
				rs.close();
				st.close();
             %>
          </table>
        </div></td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
